package com.gyms.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.classic.okhttp.beans.HVAreaBean;
import com.gyms.R;

import java.util.List;

import click.OnRecyclerViewItemClick;

/**
 * Created by ltx on 17/12/28
 */

public class AreaAdapter extends RecyclerView.Adapter<AreaAdapter.AreaViewHolder> {
    private List<HVAreaBean> mHVAreaBeans;
    private Context mContext;
    private OnRecyclerViewItemClick mOnRecyclerViewItemClick;
    private static final String S_SELCTED_COLOR="#c33055";
    private static final String S_NOM_COLOR="#333333";

    public AreaAdapter(Context mContext) {
        this.mContext=mContext;
    }

    @Override
    public AreaViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View mView= LayoutInflater.from(mContext).inflate(R.layout.ll_area_item,parent,false);
        return new AreaViewHolder(mView);
    }

    @Override
    public void onBindViewHolder(AreaViewHolder holder, int position) {
        HVAreaBean mAreaBean=mHVAreaBeans.get(position);
        holder.itemView.setTag(position);
        holder.mAreaName.setText(mAreaBean.name);
        holder.mAreaName.setTextColor(mAreaBean.isSelected? Color.parseColor(S_SELCTED_COLOR):Color.parseColor(S_NOM_COLOR));
    }

    @Override
    public int getItemCount() {
        return null==mHVAreaBeans?0:mHVAreaBeans.size();
    }

    public void setHVAreaBeans(List<HVAreaBean> HVAreaBeans) {
        mHVAreaBeans = HVAreaBeans;
    }


    public void setOnRecyclerViewItemClick(OnRecyclerViewItemClick onRecyclerViewItemClick) {
        mOnRecyclerViewItemClick = onRecyclerViewItemClick;
    }

    class AreaViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        private TextView mAreaName;
        private AreaViewHolder(View itemView) {
            super(itemView);
            mAreaName= (TextView) itemView.findViewById(R.id.tv_area_name);
            itemView.setOnClickListener(this);
        }

         @Override
         public void onClick(View v) {
             switch (v.getId()){
                 case R.id.rl_area_item:
                     int mPosition= (int) v.getTag();
                     if(null!=mOnRecyclerViewItemClick){
                         mOnRecyclerViewItemClick.onRecyclerItemClick((RecyclerView) v.getParent(),mPosition);
                     }
             }
         }
     }
}

